////////////////////////////////////////////////////////////////////////////////
//
//	Original file Name: InputDeviceGroup.java
//	Originating Author: JWhitefield
//	
//	Description: Input Device Group describes a group of input devices which can be used to control one thing at the same time
//
////////////////////////////////////////////////////////////////////////////////

package com.jjw.game.input;

import java.util.ArrayList;
import java.util.List;

/**
 * Input Device Group describes a group of input devices which can be used to control one thing at the same time
 * 
 * @author JWhitefield
 *
 */
public class InputDeviceGroup extends InputDevice implements IInputMenu,IInputPlayer {

	//--------------------------------------------------------------------------
	//
	//Properties
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	// Public
	//----------------------------------
	
	//----------------------------------
	//  Getters / Setters
	//----------------------------------
	
	//----------------------------------
	// Private
	//----------------------------------
	
	/**
	 * List of the input devices which exist  within this group 
	 */
	private List<InputDevice> inputDevices;
	
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	// Public
	//----------------------------------
	
	InputDeviceGroup() {
		
		//Setup the input device list
		this.inputDevices = new ArrayList<InputDevice>();
	}
	
	/**
	 * Sets the list of input devices that are within this input group 
	 * 
	 * @param inputDevices	list of devices
	 */
	void setInputDeviceGroup( List<InputDevice> inputDevices ) {
		
		//If the list is null, empty our list and return 
		if( inputDevices == null )
		{
			this.inputDevices.clear();
			return;
		}
		
		//Set the input device list
		this.inputDevices = inputDevices;
	}
	
	//----------------------------------
	// Private
	//----------------------------------
	
	//----------------------------------
	// Overridden / Implemented
	//----------------------------------

	@Override
	public InputButton getUpInputButton() {
		
		//Loop through each of the devices in the group
		//If the button we are looking for is down then return that instance of the button 
		for( InputDevice device : this.inputDevices  )
			if( device.getUpInputButton().isDown() )
				return device.getUpInputButton();
		
		//Return the button from the super class
		return super.getUpInputButton();
	}

	@Override
	public InputButton getDownInputButton() {

		//Loop through each of the devices in the group
		//If the button we are looking for is down then return that instance of the button 
		for( InputDevice device : this.inputDevices  )
			if( device.getDownInputButton().isDown() )
				return device.getDownInputButton();
		
		//Return the button from the super class
		return super.getDownInputButton();
	}

	@Override
	public InputButton getLeftInputButton() {

		//Loop through each of the devices in the group
		//If the button we are looking for is down then return that instance of the button 
		for( InputDevice device : this.inputDevices  )
			if( device.getLeftInputButton().isDown() )
				return device.getLeftInputButton();
		
		//Return the button from the super class
		return super.getLeftInputButton();
	}

	@Override
	public InputButton getRightInputButton() {
		
		//Loop through each of the devices in the group
		//If the button we are looking for is down then return that instance of the button 
		for( InputDevice device : this.inputDevices  )
			if( device.getRightInputButton().isDown() )
				return device.getRightInputButton();
		
		//Return the button from the super class
		return super.getRightInputButton();
	}

	@Override
	public InputButton getAttackInputButton() {

		//Loop through each of the devices in the group
		//If the button we are looking for is down then return that instance of the button 
		for( InputDevice device : this.inputDevices  )
			if( device.getAttackInputButton().isDown() )
				return device.getAttackInputButton();
		
		//Return the button from the super class		
		return super.getAttackInputButton();
	}

	@Override
	public InputButton getSelectInputButton() {
		
		//Loop through each of the devices in the group
		//If the button we are looking for is down then return that instance of the button 
		for( InputDevice device : this.inputDevices  )
			if( device.getSelectInputButton().isDown() )
				return device.getSelectInputButton();
		
		//Return the button from the super class
		return super.getSelectInputButton();
	}	
	
}